using System.Collections;
using NUnit.Framework;
using Scenario.WorkflowEngine.DataBase;
using Scenario.WorkflowEngine.DataModel.WorkflowProcesses;
using Scenario.WorkflowEngine.Database.WorkflowProcesses;

namespace Scenario.WorkflowEngine.Scheduler.Data.TEST
{
    /// <summary>
    /// Tests to exercise Person and PersonHelper methods.
    /// </summary>
    [TestFixture]
    public class TestDataBase
    {
        #region
        [Test]
        public void SelectItemToWork()
        {
            IList items = Helpers.ExchangeItem().SelectItemToWork();
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                ExchangeItem item = (ExchangeItem)enumerator.Current;
                System.Console.Out.WriteLine(item.Id);
            }
        }
        #endregion

        #region Activity
        [Test]
        public void DynamicGetActivityList()
        {
            Activity activity = new Activity();
            /*activity.ProcessId = 1;
            activity.ActivityId = "Start";
            */
            activity.ProcessName = "TestNotePad";
            IList items = Helpers.ActivityHelper().DynamicGetActivityList(activity);
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                Activity item = (Activity)enumerator.Current;
                System.Console.Out.WriteLine("{0} {1} {2}", item.ProcessId, item.ActivityId,item.Name);
            }
        }

        [Test]
        public void GetActivityNotCompleted()
        {
            Activity activity = new Activity();
            activity.Status = "NotCompleted";

            IList items = Helpers.ActivityHelper().DynamicGetActivityList(activity);
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                Activity item = (Activity)enumerator.Current;
                System.Console.Out.WriteLine("{0} {1} {2}", item.ProcessId, item.ActivityId, item.Name);
            }
        }

        [Test]
        public void SelectActivity()
        {
            IList items = Helpers.ActivityHelper().SelectAllActivities ();
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                Activity item = (Activity)enumerator.Current;
                System.Console.Out.WriteLine(item.ProcessId);
            }
        }
        #endregion

        #region Workflow
        [Test]
        public void SelectWorkflow()
        {
            IList items = Helpers.WorkflowHelper().SelectAllWorkflow();
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                XMLWorkflow item = (XMLWorkflow)enumerator.Current;
                System.Console.Out.WriteLine(item.ProcessId);
            }
        }

        [Test]
        public void DynamicGetWorkflowList()
        {
            XMLWorkflow workflow = new XMLWorkflow();
            workflow.ProcessId = "";
            IList items = Helpers.WorkflowHelper().DynamicGetWorkflowList(workflow);
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                XMLWorkflow item = (XMLWorkflow)enumerator.Current;
                System.Console.Out.WriteLine(item.ProcessId);
            }
        }
        #endregion

        [Test]
        public void AddSignal()
        {
            // insert it
            ExchangeItem item = new ExchangeItem();
            item.Object = "Segnale";
            item.Priority = 0;
            item.ProcessXML = "<Signal><Execution ProcessName=\"StartEnd\" Running=\"Immediate\"/></Signal>";
            item.Source = "ExternalSystem";
            item.Target = "NA";
            Helpers.ExchangeItem().Insert(item);
        } 

        [Test]
        public void ExchangeItemInsert()
        {
            // insert it
            ExchangeItem item = new ExchangeItem();
            item.Object = "Message";
            item.Priority = 0;
            item.ProcessXML = "<ok></ok>";
            item.Source = "Provolone";
            item.Target = "Oktarget";
            Helpers.ExchangeItem().Insert(item);
        }

        #region KPI
        [Test]
        public void DynamicGetKPIList()
        {
            KPI kpi = new KPI();
            kpi.Id = "prova";

            IList items = Helpers.KPIHelper().DynamicGetKPIList (kpi);
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                KPI item = (KPI)enumerator.Current;
                System.Console.Out.WriteLine("{0} {1} {2} {3} {4} {5}", item.Id, item.Name, item.Value, item.Start, item.Stop, item.Elapsed);
            }
        }

        [Test]
        public void SelectKPI()
        {
            IList items = Helpers.KPIHelper().SelectAllKPIs();
            IEnumerator enumerator = items.GetEnumerator();
            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                KPI item = (KPI)enumerator.Current;
                System.Console.Out.WriteLine("{0} {1} {2} {3} {4} {5}", item.Id, item.Name, item.Value, item.Start, item.Stop, item.Elapsed);
            }
        }
        #endregion

    }
}